#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
//创建线程测试函数
void* thread_testFunc(void *arg){
    printf("Thread1 is running\n");

    // 模拟一些工作
    sleep(3);
    printf("Thread1 is ending\n");
    return NULL;
}

int main(int argc, char const *argv[])
{
    printf("Main thread started\n");
    pthread_t tr1;
    pthread_create(&tr1, NULL, thread_testFunc, NULL);
    pthread_cancel(tr1); // 取消线程
    void *res;
    pthread_join(tr1, &res);
    //判断线程是否被取消
    if (res == PTHREAD_CANCELED) {
        printf("Thread1 was canceled\n");
    } else {
        printf("Thread1 completed normally\n");
    }
    printf("Main thread ended\n");
    return 0;
}
